<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/WEB-INF/jsp/common/include_easyui.jsp"></jsp:include>
<script type="text/javascript">
jQuery(function(){
	var loadURL = "<%=path%>/roleMgrController/loadMenuTree";
	jQuery("#tree_div").tree({
		
		method:			"get",
		url:			loadURL,
		lines:			true,
		checkbox:		true
	});
	
})
function saveData(){
	
	var isValid = jQuery("#addForm").form('validate');
	if(!isValid){
		jQuery("#addForm").form('enableValidation');
	}else{
		var checkNodes = jQuery('#tree_div').tree('getChecked', ['checked','indeterminate']);
		var idArray = new Array();
		for(var i = 0;i<checkNodes.length;i++){
			var jsonObj = checkNodes[i];
			var id = jsonObj.id;
			idArray.push(id);
		}
		var roleMenuData = idArray.join(",");
		jQuery("#roleMenuData").val(roleMenuData);
		
		var saveURL = "<%=path%>/roleMgrController/addRole?date="+new Date()+"";
		var paramObj = jQuery("#addForm").serializeArray();
		
		//alert(jQuery("#addForm").serialize())

		jQuery.post(saveURL,paramObj,function(responseData){
			var code = responseData.code;
			if (code == "200"){
				
				$.messager.confirm('提示对话框', '数据添加成功，是否继续添加?', function(flag){
					if (flag){
						jQuery("#addForm").form("reset");
						jQuery("#tree_div").tree("reload");
					}else{
						var parentWin = window.parent;
						parentWin.jQuery("#div_table").datagrid("reload");
						parentWin.jQuery('#dialog_div').dialog("close");
					}
				});

			}else{
				$.messager.alert('我的消息',"数据保存出错，原因 ：" + responseData.message,'error');
			}
			
		},"json");
	}
	
	
	
	
}
</script>

<style type="text/css">


.add-form div{
	margin-bottom:20px;
/* 	display: flex;
    justify-content:center; */
}
	

.add-form div input{
	max-width: 400px;
	height:28px;
	width:100%;
}
</style>
  </head>
  
  <body>
		<form id="addForm" method="post" class="add-form">
			<div style="padding-left:12%;margin-top:30px;width: 80%;">
				<input class="easyui-textbox" name="roleName" labelAlign="right" data-options="label:'角色名称：',required:true">
			</div>
			<div style="padding-left:12%;width: 80%;">
				<input class="easyui-textbox" name="roleRemark" labelAlign="right" data-options="label:'角色备注：',required:true">
			</div>
			<div style="padding-left:12%;width: 80%;">
				<label class="textbox-label textbox-label-before" style="float:left;text-align: right; height: 38px; line-height: 38px;">角色权限：</label>
				<div id="tree_div" style="padding-left:40px;padding-top:25px;float:left;height:235px;width: 277px;overflow-y: scroll;border: 1px solid #95B8E7;"></div>
   				<Input type="hidden" name="roleMenuData" id="roleMenuData"/>
			</div>
		</form>

  </body>
</html>
